package com.study.designpattern.singleton;

import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public enum EnumSingleton {
    INSTANCE;
    public void print(){
        System.out.println(this.hashCode());
    }
}
class EnumTest{
    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, IOException, ClassNotFoundException {
//        Constructor<EnumSingleton> declaredConstructor = EnumSingleton.class.getDeclaredConstructor(String.class,int.class);
//        declaredConstructor.setAccessible(true);
//        EnumSingleton enumSingleton = declaredConstructor.newInstance("INSTANCE",0);
        EnumSingleton instance=EnumSingleton.INSTANCE;
//        ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("EnumSingletonSerialization"));
//        oos.writeObject(instance);
//        oos.close();
        ObjectInputStream ois=new ObjectInputStream(new FileInputStream("EnumSingletonSerialization"));
        EnumSingleton instance1=(EnumSingleton) ois.readObject();
        ois.close();
        System.out.println(instance);
        System.out.println(instance1);
    }
}